package 缓冲流专属;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class Demo02 {

	public static void main(String[] args)  {
		
		//测试没用缓冲流的运行时间
		
		long start = System.currentTimeMillis();
		
		getCopy("D:\\中软学习\\视频\\day31 递归\\文件夹遍历12.mp4","E:\\文件夹遍历.mp4");
		
		long end = System.currentTimeMillis();
		
		System.out.println("运行时长：" + (end - start)); //运行时长：4487
					

	}
	
	public static void getCopy(String str1 , String str2){
		// 文件复制 使用缓冲区
		
				//创建字节流对象
				FileInputStream fis = null;
				FileOutputStream fos = null;
				
				
				try {
					fis = new FileInputStream(str1);
					
					fos = new FileOutputStream(str2);
					
					//复制
					byte[] by = new byte[1024];
					int len;
					while((len = fis.read(by)) != -1){
						fos.write(by,0,len);
					}
					
					//刷新 有处理流了 就不用刷新字节输出流了
					fos.flush();
					
				} catch (FileNotFoundException e) {
					
					e.printStackTrace();
				} catch (IOException e) {

					e.printStackTrace();
				} finally {
					
					if( fos != null){
						try {
							fos.close();
						} catch (IOException e) {
							e.printStackTrace();
						}
					}
					
					if( fis != null){
						try {
							fis.close();
						} catch (IOException e) {
							e.printStackTrace();
						}
					}
					
				}
	}

}
